
#import "LanBLogger.h"

@implementation LanBLogger

NS_INLINE NSDateFormatter * formatter () {
    static NSDateFormatter *f;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!f) {
            f = [[NSDateFormatter alloc] init];
            f.dateFormat = @"yyyy-MM-dd HH:mm:ss.SSS";
        }
    });
    return f;
}

+ (void)lanB_log:(NSString *)fileName method:(NSString *)method lineNr:(NSNumber *)lineNr text:(NSString *)formatStr
{
#ifdef DEBUG
    if (formatStr.length > 0) {
        __block NSString* logText = formatStr?formatStr:@"";
        NSString *now = [formatter() stringFromDate:NSDate.date];
        logText = [NSString stringWithFormat:@"\n< %@ >\n< %@ %@ -Line:%@ >\n%@\n\n", now, fileName, method, lineNr.stringValue, logText];
        fprintf(stderr, "%s", logText.UTF8String);
    }
#endif
}

@end

